package com.tywj.buscustomerapp.view.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.tywj.buscustomerapp.R;
import com.tywj.buscustomerapp.model.bean.BusTravelBean;
import com.tywj.buscustomerapp.model.bean.DateJoe;
import com.tywj.buscustomerapp.model.bean.DaysNew;
import com.tywj.buscustomerapp.model.bean.RequestBean;
import com.tywj.buscustomerapp.model.bean.StationBean;
import com.tywj.buscustomerapp.presenter.BasePresenter;
import com.tywj.buscustomerapp.presenter.contract.BuyTicketContract;
import com.tywj.buscustomerapp.presenter.contract.newBuyTicketContract;
import com.tywj.buscustomerapp.presenter.newBuyTicketPresenter;
import com.tywj.buscustomerapp.utils.SPUtils;
import com.tywj.buscustomerapp.utils.TaylorClickLinstener;
import com.tywj.buscustomerapp.utils.TimeRender;
import com.tywj.buscustomerapp.utils.myadapter.CommonRcvAdapter;
import com.tywj.buscustomerapp.utils.myadapter.item.AdapterItem;
import com.tywj.buscustomerapp.view.item.DaysItem;
import com.tywj.buscustomerapp.view.myview.LoadingDialog;
import com.tywj.buscustomerapp.view.myview.ToastJoe;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

public class newBuyTicketActivity extends BaseActivityMvp implements newBuyTicketContract.newBuyTicketView{
    private String Tag="newBuyTicketActivity";
    private newBuyTicketContract.newBuyTicketPresenter presenter = new newBuyTicketPresenter(this);
    @BindView(R.id.head_left)
    ImageView back;
    @BindView(R.id.head_title)
    TextView title;
    @BindView(R.id.dateRecycler)
    RecyclerView dateRecycler;
    @BindView(R.id.ticket_once)
    LinearLayout onceTicketLayout;
    @BindView(R.id.ticket_once_about) TextView onceTicketAbout;
    @BindView(R.id.location_start) LinearLayout locationStart;
    @BindView(R.id.location_end) LinearLayout locationEnd;
    @BindView(R.id.check_ticktes) TextView checkTicketNumber;
    @BindView(R.id.buyticket_checkline1) LinearLayout checkLine1;
    @BindView(R.id.start) TextView start;
    @BindView(R.id.end) TextView end;
    @BindView(R.id.line_gry) View lineGry;
    @BindView(R.id.total_price) TextView total_price;
    @BindView(R.id.submit) TextView submit;
    @BindView(R.id.month_ticket_time) TextView month_time;

    //月票
    @BindView(R.id.month_par)
    ConstraintLayout month_par;
    @BindView(R.id.textView9)
    TextView month_name;
    @BindView(R.id.textView11)
    TextView mont_cont_day;
    @BindView(R.id.textView10)
    TextView textView10;
    @BindView(R.id.textView12)
    TextView old_price;
    @BindView(R.id.buyticket_checkline2)
    LinearLayout linearLayout;
    @BindView(R.id.textView13)
    TextView month_price;
    public boolean isCheck = false;

    private List<DaysNew.DataBean> dates = new ArrayList<>();//日历
    private CommonRcvAdapter<DaysNew.DataBean> adapter;
    private DaysItem item;
    private BusTravelBean.DataBean.ResultListBean busLineBean;
    private List<String> startStations = new ArrayList<>();//开始站点s
    private List<String> startStationsId = new ArrayList<>();//开始站点Ids
    private List<String> endStations = new ArrayList<>();//结束站点s
    private List<String> endStationsId = new ArrayList<>();//结束站点ids
    private String chooseStart ="";//选择的起始站点
    private String chooseStartId ="";//选择的起始站点id
    private String chooseEnd ="";//选择的结束站点
    private String chooseEndId ="";//选择的结束站点id
    private OptionsPickerView tvStart;
    private OptionsPickerView tvEnd;
    private int postition = 0;
    private String price = "0";//显示的最终价格
    private List<DaysNew.DataBean> checkTickets=new ArrayList<>();//已选择的日期
    private int number = 1;
    public static newBuyTicketActivity activity;




    @Override
    public int getLayoutResId() {
//        return R.layout.activity_but_ticket;
        return R.layout.activity_buy_ticket;
    }

    @Override
    public void initView() {
        activity = this;
        back.setOnClickListener(this);
        locationStart.setOnClickListener(this);
        locationEnd.setOnClickListener(this);
        checkLine1.setOnClickListener(this);
        month_par.setOnClickListener(this);
//        add.setOnClickListener(this);
//        low.setOnClickListener(this);
        onceTicketAbout.setOnClickListener(this);
        old_price.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);
        adapter = new CommonRcvAdapter<DaysNew.DataBean>(dates) {
            @NonNull
            @Override
            public AdapterItem createItem(Object type) {
                item = new DaysItem();
                item.setListener(new DaysItem.OnCheckListener() {
                    @Override
                    public void onChecked(DaysNew.DataBean date, int position, View view) {
                        CheckMonth(true);
                        if (chooseStartId.equals("")){
                            ToastJoe.getmToastJoe().ToastShow(newBuyTicketActivity.this,null,"请选择上车站点");
                            date.setCheck(false);
                            adapter.notifyItemChanged(position,date);
                        }else if (chooseEndId.equals("")){
                            ToastJoe.getmToastJoe().ToastShow(newBuyTicketActivity.this,null,"请选择下车站点");
                            date.setCheck(false);
                            adapter.notifyItemChanged(position,date);
                        }
                        else{
                            if (TimeRender.compareTime666(date.getRiqi()+" "+busLineBean.getFcsj())){
                                showDialog("温馨提示","该班次已发车，发车后无法退票，请确认是否购买",date,position);
                            }else {
                                checkTickets.add(date);
                                ChangeToatalMoney();
                            }
                        }
                    }

                    @Override
                    public void onDeleted(DaysNew.DataBean date) {
                        checkTickets.remove(date);
                        ChangeToatalMoney();
                    }
                });
                return item;
            }
        };
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,7);
        dateRecycler.setLayoutManager(layoutManager);
        dateRecycler.setAdapter(adapter);
        String[] thisTime = TimeRender.getFullDateStr9();
        month_time.setText(thisTime[0]+"年"+thisTime[1]+"月");

        submit.setOnClickListener(new TaylorClickLinstener() {
            @Override
            public void onMultiClick(View v) {
                if (isCheck){
                    if (isStartEnd()) {
                        ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this, null, "终点站必须在起始站之后");
                    } else {
                        doBuying();
                    }
                }else {
                    //购买单程票
                    if (checkTickets.size() < 1) {
                        ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this, null, "请选择乘车日期");
                    } else if (price.equals("0")) {
                        price = busLineBean.getXlpj();
                        doBuying();
                    } else if (isStartEnd()) {
                        ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this, null, "终点站必须在起始站之后");
                    } else {
                        doBuying();
                    }
                }
            }
        });
    }

    @Override
    public void initData() {
        String phone = SPUtils.getUserPhone(getApplicationContext());
        if (getIntent()!=null){
            showLoading();
            busLineBean = (BusTravelBean.DataBean.ResultListBean) getIntent().getSerializableExtra("bus");
            if (busLineBean!=null){
                price = busLineBean.getXlpj();
                drewDialog();
                title.setText(busLineBean.getXlmc());
                if (startStationsId.size()==0 && busLineBean.getStations().size()>0){
                    for (int i = 0; i < busLineBean.getStations().size()-1; i++) {
                        startStations.add(busLineBean.getStations().get(i).getZmc());
                        startStationsId.add(busLineBean.getStations().get(i).getId()+"");
                    }
                    for (int i = postition+1; i < busLineBean.getStations().size(); i++) {
                        endStations.add(busLineBean.getStations().get(i).getZmc());
                        endStationsId.add(busLineBean.getStations().get(i).getId()+"");
                    }
                }
                chooseStart = busLineBean.getStations().get(0).getZmc();
                chooseStartId = busLineBean.getStations().get(0).getId()+"";
                chooseEnd = busLineBean.getStations().get(busLineBean.getStations().size()-1).getZmc();
                chooseEndId = busLineBean.getStations().get(busLineBean.getStations().size()-1).getId()+"";
                start.setText(chooseStart);
                end.setText(chooseEnd);
                presenter.getDays(busLineBean.getXlbh(),phone);
                setMontView();
            }else{
                String linnum = getIntent().getStringExtra("lineNum");
                presenter.getLineMessage(linnum);
            }
        }


    }

    private void setMontView(){
        if (busLineBean!=null && busLineBean.getSfyp()!=null && busLineBean.getYpOpenTime()!=null){
            if (busLineBean.getSfyp().equals("1") && busLineBean.getYpOpenTime().equals("true")){
                month_par.setVisibility(View.VISIBLE);
                linearLayout.setVisibility(View.VISIBLE);
                old_price.setText("￥"+Integer.valueOf(busLineBean.getYpDays())*Integer.valueOf(busLineBean.getXlpj()));
                mont_cont_day.setText("共计"+busLineBean.getYpDays()+"天");
                month_name.setText(TimeRender.getMonth()+"月月票");
                double one_price = Double.valueOf(busLineBean.getYpjg());
                int cout = Integer.valueOf(busLineBean.getYpDays());
                double price = one_price * cout;
                BigDecimal d = new BigDecimal(price);
                month_price.setText("￥"+d.setScale(2,   RoundingMode.HALF_UP).doubleValue());
            }else{
                month_par.setVisibility(View.GONE);
                linearLayout.setVisibility(View.GONE);
            }
        }else{
            month_par.setVisibility(View.GONE);
            linearLayout.setVisibility(View.GONE);
        }
    }
    private boolean isStartEnd(){
        List<BusTravelBean.DataBean.ResultListBean.StationsBean> list = busLineBean.getStations();
        if (list!=null && list.size()>0 && chooseStartId!=null && chooseEndId !=null){
            int start = 0;
            int end =0;
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getId()==Integer.valueOf(chooseStartId)){
                    start = Integer.valueOf(list.get(i).getZbh());
                }
                if (list.get(i).getId()==Integer.valueOf(chooseEndId)){
                    end = Integer.valueOf(list.get(i).getZbh());
                }
            }
            if (end>start){
                return false;
            }
        }
        return true;
    }

    private void doBuying(){
        if (isCheck){
            presenter.doBuyTicketMonth(newBuyTicketActivity.this, SPUtils.getUserPhone(getApplicationContext())
                    , busLineBean.getXlbh(), chooseStartId
                    , chooseEndId);
        }else {
            String statTime = "";
            String endTime = "";
            for (int j = 0; j < busLineBean.getStations().size(); j++) {
                if (chooseStartId.equals(busLineBean.getStations().get(j).getId() + "")) {
                    statTime = busLineBean.getStations().get(j).getDzsj();
                }
                if (chooseEndId.equals(busLineBean.getStations().get(j).getId() + "")) {
                    endTime = busLineBean.getStations().get(j).getDzsj();
                }
            }
            List<String> datas = new ArrayList<>();
            for (int i = 0; i < checkTickets.size(); i++) {
                datas.add(checkTickets.get(i).getRiqi());
            }
            presenter.doBuyTicketOnOnce(newBuyTicketActivity.this, SPUtils.getUserPhone(getApplicationContext())
                    , busLineBean.getXlbh(), chooseStartId
                    , chooseEndId, datas, statTime, endTime, number);
        }
    }



    @Override
    protected BasePresenter bindPresenter() {
        return presenter;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.head_left:
                finish();
                break;
            case R.id.location_start:
                if (startStationsId.size()==0 && busLineBean.getStations().size()>0){
                    for (int i = 0; i < busLineBean.getStations().size()-1; i++) {
                        startStations.add(busLineBean.getStations().get(i).getZmc());
                        startStationsId.add(busLineBean.getStations().get(i).getId()+"");
                    }
                }
                tvStart.show(v);
                break;
            case R.id.location_end:
                if (chooseStartId.equals("")){
                    ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this,null,"请先选择出发站");
                }else {
                    ClearEndStation();
                    tvEnd.show(v);
                }
                break;
            case R.id.ticket_once_about:
                Intent intent = new Intent(newBuyTicketActivity.this,InfoActivity.class);
                intent.putExtra("type",1);
                startActivity(intent);
                break;
            case R.id.month_par:
                CheckMonth(isCheck);
                break;
        }


    }

    private void CheckMonth(boolean is){
        if (is){//不选
            month_par.setBackgroundResource(R.drawable.bg_white_shape1_1);
            mont_cont_day.setTextColor(getResources().getColor(R.color.text));
            month_name.setTextColor(getResources().getColor(R.color.text));
            old_price.setTextColor(getResources().getColor(R.color.text_help));
            textView10.setTextColor(getResources().getColor(R.color.text_help));
            price = busLineBean.getXlpj();
            isCheck = !is;
            ChangeToatalMoney();
        }else{//选
            month_par.setBackgroundResource(R.drawable.bg_ori_shape1);
            mont_cont_day.setTextColor(getResources().getColor(R.color.white));
            month_name.setTextColor(getResources().getColor(R.color.white));
            old_price.setTextColor(getResources().getColor(R.color.white));
            textView10.setTextColor(getResources().getColor(R.color.white));
            checkTickets.clear();
            List<DaysNew.DataBean> dateJoes = adapter.getData();
            for (int i = 0; i < dateJoes.size(); i++) {
                dateJoes.get(i).setCheck(false);
            }
            adapter.setData(dateJoes);
            adapter.notifyDataSetChanged();
            price =month_price.getText().toString();
            total_price.setText(month_price.getText().toString());
            checkTicketNumber.setText("共选择1张月票");
            isCheck = !is;
        }

    }

    private LoadingDialog waitDialog;
    @Override
    public void showLoading() {
        if (waitDialog==null)
            waitDialog = new LoadingDialog(newBuyTicketActivity.this);
        if (!waitDialog.isShowing())
            waitDialog.show();
    }

    @Override
    public void closeLoading() {
        if (waitDialog!=null && waitDialog.isShowing())
            waitDialog.dismiss();
    }

    @Override
    public void loadError(String msg) {
        closeLoading();
        ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this,null,msg);
    }

    @Override
    public void loadDays(List<DaysNew.DataBean> days) {
        closeLoading();
        int num = days.size();
        for (int i = 0; i < num; i++) {
            days.get(i).setPrice(busLineBean.getXlpj());
        }

        adapter.setData(days);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void loadeIsBuySuccess(RequestBean requestBean) {
        closeLoading();
        if (requestBean.getReCode().equals("201")){
            Intent intent = new Intent(newBuyTicketActivity.this,PayActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt("position",0);
            bundle.putSerializable("bean",busLineBean);
            bundle.putSerializable("list", (Serializable) checkTickets);
            bundle.putString("start", chooseStart+"("+busLineBean.getStations().get(startStationsId.indexOf(chooseStartId)).getDzsj()+")");
            int endId = 0;
            for (int i = 0; i < busLineBean.getStations().size(); i++) {
                if (busLineBean.getStations().get(i).getId()==Integer.valueOf(chooseEndId)){
                    endId = i;
                }
            }
            bundle.putString("end", chooseEnd+"("+busLineBean.getStations().get(endId).getDzsj()+")");
            bundle.putString("price",price);
            bundle.putSerializable("pay",requestBean);
            bundle.putInt("number",number);
            intent.putExtras(bundle);
            startActivity(intent);
        }else if (requestBean.getReCode().equals("202")){
            // TODO: 2018/7/2 这里跳转到车票界面展示周期票
            ToastJoe.getmToastJoe().ToastShowRight(getApplicationContext(),null,"购买成功");
            Intent intent = new Intent(newBuyTicketActivity.this, MyTicketActivity.class);
            startActivity(intent);
            newBuyTicketActivity.activity.finish();
            finish();
        }else{
            ToastJoe.getmToastJoe().ToastLongShow(this,null,requestBean.getCodeTxt());
        }
    }

    @Override
    public void loadeLineMessage(BusTravelBean.DataBean.ResultListBean bean) {
        busLineBean = bean;
//        Log.i("NEWBUY",bean.toString());
        if (busLineBean!=null){
            price = busLineBean.getXlpj();
            drewDialog();
            title.setText(busLineBean.getXlmc());
            if (startStationsId.size()==0 && busLineBean.getStations().size()>0){
                for (int i = 0; i < busLineBean.getStations().size()-1; i++) {
                    startStations.add(busLineBean.getStations().get(i).getZmc());
                    startStationsId.add(busLineBean.getStations().get(i).getId()+"");
                }
                for (int i = postition+1; i < busLineBean.getStations().size(); i++) {
                    endStations.add(busLineBean.getStations().get(i).getZmc());
                    endStationsId.add(busLineBean.getStations().get(i).getId()+"");
                }
            }
            chooseStart = busLineBean.getStations().get(0).getZmc();
            chooseStartId = busLineBean.getStations().get(0).getId()+"";
            chooseEnd = busLineBean.getStations().get(busLineBean.getStations().size()-1).getZmc();
            chooseEndId = busLineBean.getStations().get(busLineBean.getStations().size()-1).getId()+"";
            start.setText(chooseStart);
            end.setText(chooseEnd);
            presenter.getDays(busLineBean.getXlbh(),SPUtils.getUserPhone(getApplicationContext()));
            setMontView();
        }
    }

    @Override
    public void finishView() {
        this.finish();
    }

    private void drewDialog() {
        tvStart = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (startStations.size()>0){
                    chooseStart = startStations.get(options1);
                    chooseStartId = startStationsId.get(options1);
                    postition = options1;
                    start.setText(chooseStart);
                    if (chooseEnd!=null && !chooseEnd.equals("")){
                        if (endStationsId.contains(chooseStartId) && (endStationsId.indexOf(chooseStartId)>=endStationsId.indexOf(chooseEndId))){
                            chooseEnd = "";
                            chooseEndId= "";
                            end.setText(R.string.ticket_end);
                            ClearEndStation();
                            price = "0";
                            checkTickets.clear();
                            ChangeToatalMoney();
                        }
                    }
                }
            }
        }).setSubCalSize(15)
                .isDialog(true)
                .setSubmitColor(getResources().getColor(R.color.appColor))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.gray1))//取消按钮文字颜色
                .build();
        tvEnd = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (!(options1>=endStations.size()) &&endStations.get(options1)!=null) {
                    chooseEnd = endStations.get(options1);
                    chooseEndId = endStationsId.get(options1);
                    end.setText(chooseEnd);
                    price = busLineBean.getXlpj();
                    ChangeToatalMoney();
                }else{
                    chooseEnd = endStations.get(endStations.size()-1);
                    chooseEndId = endStationsId.get(endStationsId.size()-1);
                    end.setText(chooseEnd);
                    price = busLineBean.getXlpj();
                    ChangeToatalMoney();
                }
            }
        }).setSubCalSize(15)
                .isDialog(true)
                .setSubmitColor(getResources().getColor(R.color.appColor))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.gray1))//取消按钮文字颜色
                .build();
        Dialog mDialog = tvStart.getDialog();
        Dialog mDialog1 = tvEnd.getDialog();
        if (mDialog != null && mDialog1!=null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);
            params.leftMargin = 0;
            params.rightMargin = 0;
            tvStart.getDialogContainerLayout().setLayoutParams(params);
            tvEnd.getDialogContainerLayout().setLayoutParams(params);

            Window dialogWindow = mDialog.getWindow();
            if (dialogWindow != null) {
                dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
                WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                dialogWindow.setAttributes(lp);
                dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);//修改动画样式
                dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
            }
            Window dialogWindow1 = mDialog1.getWindow();
            if (dialogWindow1 != null) {
                dialogWindow1.getDecorView().setPadding(0, 0, 0, 0);
                WindowManager.LayoutParams lp = dialogWindow1.getAttributes();
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                dialogWindow1.setAttributes(lp);
                dialogWindow1.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);//修改动画样式
                dialogWindow1.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
            }
        }
        tvStart.setPicker(startStations, null, null);
        tvEnd.setPicker(endStations, null, null);
    }

    private void ClearEndStation(){
        endStations.clear();
        endStationsId.clear();
        for (int i = postition+1; i < busLineBean.getStations().size(); i++) {
            endStations.add(busLineBean.getStations().get(i).getZmc());
            endStationsId.add(busLineBean.getStations().get(i).getId()+"");
        }
    }

    private void ChangeToatalMoney(){
        if (price!=null && !price.equals("")) {
            int num = checkTickets.size()*number;
            if (isCheck)
                total_price.setText("￥" + price);
            else
                total_price.setText("￥" + (num * Double.valueOf(price)));

            checkTicketNumber.setText("共选择" + num + "张车票");
        }else{
            ToastJoe.getmToastJoe().ToastLongShow(newBuyTicketActivity.this,null,"线路信息错误");
            finish();
        }
    }


    private AlertDialog build;
    private void showDialog(final String title, final String msg, final DaysNew.DataBean dateJoe, final int pos){
        build = new AlertDialog.Builder(newBuyTicketActivity.this,R.style.AlertDialogStyle).create();
        //自定义布局
        View view = getLayoutInflater().inflate(R.layout.dialog_nopay_layout, null);
        build.setView(view, 0, 0, 0, 0);
        build.show();
        //得到当前显示设备的宽度，单位是像素
        int width = getWindowManager().getDefaultDisplay().getWidth();
        //得到这个dialog界面的参数对象
        WindowManager.LayoutParams params = build.getWindow().getAttributes();
        //设置dialog的界面宽度
        params.width = width-(width/3);
        //设置dialog高度为包裹内容
        params.height =  WindowManager.LayoutParams.WRAP_CONTENT;
        //设置dialog的重心
        params.gravity = Gravity.CENTER;
        build.getWindow().setAttributes(params);
        build.setCanceledOnTouchOutside(false);
        TextView titleTv = view.findViewById(R.id.message);
        TextView messageTv = view.findViewById(R.id.message1);
        titleTv.setText(title);
        messageTv.setText(msg);
        Button btn_sure = view.findViewById(R.id.yes);
        Button btn_cancel = view.findViewById(R.id.no);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkTickets.add(dateJoe);
                ChangeToatalMoney();
                build.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dateJoe.setCheck(false);
                adapter.notifyItemChanged(pos,dateJoe);
                build.dismiss();
            }
        });
    }

    @Override
    public Context getViewContext() {
        return this;
    }
}
